{% load debate_tags i18n humanize %}

<div class="card">

  <div class="card-body">
    <h5 class="card-title mb-0">
      {% if type == "teams" %}{% trans "Teams" %}
      {% elif type == "adjs" %}{% trans "Adjudicators" %}
      {% elif type == "venues" %}{% trans "Rooms" %}
      {% endif %}
    </h5>
  </div>

  <div class="list-group list-group-flush">

    <div class="list-group-item">
      <div class="d-flex justify-content-end">
        <span class="mr-auto">{{ round.name }}</span>
        <strong>{{ info.in_now }}/{{ info.total }}</strong>
      </div>
      {% include "components/progress-bar.html" with value=info.in_now total=info.total type="success" %}
    </div>

    {% if info.in_before is not None %}
      <div class="list-group-item">
        <div class="d-flex justify-content-end">
          <span class="mr-auto">{{ round.prev.name }}</span>
          <strong>{{ info.in_before }}/{{ info.total }}</strong>
        </div>
        {% include "components/progress-bar.html" with value=info.in_before total=info.total type="info" %}
      </div>
    {% endif %}

    {% if info.message %}
      <div class="list-group-item list-group-item-info">
        {{ info.message }}
      </div>
    {% endif %}

    {% if type == "teams" %}

      {% roundurl 'availability-teams' round as url %}
      {% trans "Mark teams as available" as title_text %}

      {% if round.is_break_round %}
        {% trans "No need to set team availability" as title_text %}
        {% include "components/item-info.html" with text=title_text type="secondary" nopad=True %}
      {% elif pref.teams_in_debate == 'two' and not availability_info.teams.in_now|divisibleby:2  %}
        {% trans "There is an uneven number of teams marked as available for this round." as text %}
        {% include "components/item-info.html" with type="danger" nopad=True %}
        {% include "components/item-action.html" with alone=True text=title_text type="success" to_complete=True %}
      {% elif pref.teams_in_debate == 'bp' and not availability_info.teams.in_now|divisibleby:4  %}
        {% trans "The number of teams marked as available for this round is not a multiple of 4." as text %}
        {% include "components/item-info.html" with type="danger" nopad=True %}
        {% include "components/item-action.html" with alone=True text=title_text type="success" to_complete=True %}
      {% elif info.in_now == 0 and not round.is_break_round %}
        {% include "components/item-action.html" with alone=True text=title_text type="success" to_complete=True %}
      {% else %}
        {% trans "Edit team availability" as title_text %}
        {% include "components/item-action.html" with alone=True text=title_text type="primary" %}
      {% endif %}

    {% elif type == "adjs" %}

      {% roundurl 'availability-adjudicators' round as url %}

      {% if adjs_no_t > 0 %}
        {% blocktrans trimmed asvar text count count=adjs_no_t %}
          One adjudicator does not have an associated tournament. Set their 'Tournament' field in the Edit Database area if you want them to be marked as available.
        {% plural %}
          {{ count }} adjudicators do not have an associated tournament. Set their 'Tournament' field in the Edit Database area if you want them to be marked as available.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% endif %}

      {% if new_adjs|length > 10 %}
        {% blocktrans trimmed asvar text count count=new_adjs|length %}
          {{ count }} adjudicator who was not available last round, is available this round.
        {% plural %}
          {{ count }} adjudicators who were not available last round, are available this round.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% elif new_adjs %}
        {% blocktrans trimmed asvar text count count=new_adjs|length with adjs_list=new_adjs|join:", " %}
          The following {{ count }} adjudicator, who was not available last round, is available this round: {{ adjs_list }}
        {% plural %}
          The following {{ count }} adjudicators, who were not available last round, are available this round: {{ adjs_list }}
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% endif %}

      {% if lost_adjs|length > 10 %}
        {% blocktrans trimmed asvar text count count=lost_adjs|length %}
          {{ count }} adjudicator who was available last round, is not available this round.
        {% plural %}
          {{ count }} adjudicators who were available last round, are not available this round.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% elif lost_adjs %}
        {% blocktrans trimmed asvar text count count=lost_adjs|length with adjs_list=lost_adjs|join:", " %}
          The following {{ count }} adjudicator, who was available last round, is not available this round: {{ adjs_list }}
        {% plural %}
          The following {{ count }} adjudicators, who were available last round, are not available this round: {{ adjs_list }}
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% endif %}

      {% trans "Mark adjudicators as available" as title_text %}
      {% if min_adjudicators > availability_info.adjs.in_now %}
        {# Translators: required_count is a word for a number (e.g. "two", "three", etc.) #}
        {% blocktrans trimmed asvar text with required_count=min_adjudicators|apnumber count count=min_adjudicators %}
          There needs to be at least one adjudicator marked as available, given the number of debates.
        {% plural %}
          There need to be at least {{ required_count }} adjudicators marked as available, given the number of debates.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="danger" nopad=True %}
        {% include "components/item-action.html" with alone=True text=title_text type="success" to_complete=True %}
      {% elif info.in_now == 0 %}
        {% include "components/item-action.html" with alone=True text=title_text type="success" to_complete=True %}
      {% else %}
        {% trans "Edit adjudicator availability" as title_text %}
        {% include "components/item-action.html" with alone=True text=title_text type="primary" %}
      {% endif %}

    {% elif type == "venues" %}

      {% roundurl 'availability-venues' round as url %}

      {% if new_venues|length > 10 %}
        {% blocktrans trimmed asvar text count count=new_venues|length %}
          {{ count }} room that was not available last round, is available this round.
        {% plural %}
          {{ count }} rooms that were not available last round, are available this round.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% elif new_venues %}
        {% blocktrans trimmed asvar text count count=new_venues|length with rooms_list=new_venues|join:", " %}
          The following {{ count }} room, which was not available last round, is available this round: {{ rooms_list }}
        {% plural %}
          The following {{ count }} rooms, which were not available last round, are available this round: {{ rooms_list }}
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% endif %}

      {% if lost_venues|length > 10 %}
        {% blocktrans trimmed asvar text count count=lost_venues|length %}
          {{ count }} room that was available last round, is not available this round.
        {% plural %}
          {{ count }} rooms that were available last round, are not available this round.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% elif lost_venues %}
        {% blocktrans trimmed asvar text count count=lost_venues|length with rooms_list=lost_venues|join:", " %}
          The following {{ count }} room, which was available last round, is not available this round: {{ rooms_list }}
        {% plural %}
          The following {{ count }} rooms, which were available last round, are not available this round: {{ rooms_list }}
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% endif %}

      {% if venues_no_t > 0 %}
        {% blocktrans trimmed asvar text count count=venues_no_t %}
          One room does not have an associated tournament. Set its 'Tournament' field in the Edit Database area if you want it to be marked as available.
        {% plural %}
          {{ count }} rooms do not have an associated tournament. Set their 'Tournament' field in the Edit Database area if you want them to be marked as available.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="info" nopad=True %}
      {% endif %}

      {% trans "Mark rooms as available" as title_text %}
      {% if min_venues > availability_info.venues.in_now %}
        {# Translators: required_count is a word for a number (e.g. "two", "three", etc.) #}
        {% blocktrans trimmed asvar text with required_count=min_venues|apnumber count count=min_venues %}
          There needs to be at least one room marked as available, given the number of
          debates.
        {% plural %}
          There need to be at least {{ required_count }} rooms marked as available, given
          the number of debates.
        {% endblocktrans %}
        {% include "components/item-info.html" with type="danger" nopad=True %}
        {% include "components/item-action.html" with alone=True text=title_text type="success" to_complete=True %}
      {% elif info.in_now == 0 %}
        {% include "components/item-action.html" with alone=True text=title_text type="success" to_complete=True %}
      {% else %}
        {% trans "Edit room availability" as title_text %}
        {% include "components/item-action.html" with alone=True text=title_text type="primary" %}
      {% endif %}

    {% endif %}

  </div>

</div>
